/**
 * 连接mysql
 */
const mysql = require("mysql");

// 创建mysql 连接池
const db = mysql.createPool({
    host: '127.0.0.1',
    port: 3306,
    database: 'dlc',
    user: 'root',
    password: 'root',
});


const mysql_exec = (sql = '', cb = (err, result) => {}) => {

    db.getConnection((err, conn) => {
        if(err){
            cb(err, [])
        }else{
            conn.query(sql, (err, result, filed) => {
                cb(err, result, filed);
            })
        }
    });

}


mysql_exec("select * from user", (err, result, fd) => {
    console.log(err, result, fd);
})


mysql_exec("insert into user(id) values(1)", (err, result, fd) => {
    console.log(result);
})